﻿<%@ Page Language="c#" CodeBehind="SelectReceiver.aspx.cs" AutoEventWireup="false" Inherits="UDS.SubModule.UnitiveDocument.Mail.SelectReceiverPage" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
  <title>选择收件人 </title>
  <uds:Style runat="server" Href="~/css/BasicLayout.css" />
  <script language="javascript" type="text/javascript">
  //<!--
  var listTo=null;
  var listCc=null;
  var listBcc=null;
  var fullList=null;

  function init() {
    if(fullList===null||listTo===null||listCc===null||listBcc===null) {
      listTo=document.getElementById("<%= listTO.ClientID %>");
      listCc=document.getElementById("<%= listCC.ClientID %>");
      listBcc=document.getElementById("<%= listBCC.ClientID %>");
      fullList=document.getElementById("<%= listAccount.ClientID %>");
    }
  }

  function RemoveItem(target) {
    init();
    var targetList=document.getElementById(target);

    for(var i=targetList.options.length-1;i>=0;i--) {
      var opt=targetList.options[i];
      if(opt.selected) {
        targetList.options.remove(i);
      }
    }
  }

  function AddItem(target) {
    init();
    var targetList=document.getElementById(target);

    for(var i=0;i<fullList.options.length;i++) {
      var srcOpt=fullList.options[i];
      if(!srcOpt.selected) {
        continue;
      }

      var val=(srcOpt.value+"").toLowerCase();

      // does this user exist in the target list?
      var addUser=true;
      for(var j=0;j<targetList.options.length;j++) {
        if(val===(targetList.options[j].value+"").toLowerCase()) {
          addUser=false;
          break;
        }
      }

      if(addUser) {
        var opt=new Option(srcOpt.text,srcOpt.value);
        targetList.options.add(opt);
      }
    }
  }

  function SetInitData(args) {
    /*
    * The arguments should look like:
    *  [
    *    [[name, id], [name, id], ...], // to list
    *    [[name, id], [name, id], ...], // cc list
    *    [[name, id], [name, id], ...], // bcc list
    *  ]
    */
    if(args!=null&&args.length===3) {
      init();

      var arr=args[0];
      if(arr!=null) {
        for(var i=0;i<arr.length;i++) {
          listTo.options.add(new Option(arr[i][0],arr[i][1]));
        }
      }

      arr=args[1];
      if(arr!=null) {
        for(var i=0;i<arr.length;i++) {
          listCc.options.add(new Option(arr[i][0],arr[i][1]));
        }
      }

      arr=args[2];
      if(arr!=null) {
        for(var i=0;i<arr.length;i++) {
          listBcc.options.add(new Option(arr[i][0],arr[i][1]));
        }
      }
    }
  }

  function SaveData() {
    var fnReadList=function(list) {
      var arr=[];
      for(var i=0;i<list.options.length;i++) {
        var opt=list.options[i];
        arr.push([opt.text,opt.value]);
      }
      return arr;
    };

    init();
    var pWin=window.opener;
    if(pWin) {
      var data=[fnReadList(listTo),fnReadList(listCc),fnReadList(listBcc)];
      pWin.SetData(data);
    }

    window.close();
  }
  //-->
  </script>
  <style type="text/css">
    .move_button {
      width: 60px;
      height: 24px;
      margin: 2px;
      text-align: center;
      display: block;
    }
    .selectBox {
      width: 100%;
      height: 90px;
    }
  </style>
</head>
<body background="<%= ResolveUrl("~/images/mailuserbg.gif")%>">
<table style="width: 100%; height: 100%;" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td style="padding: 20px 40px;">
      <form id="SelectReceiver" method="post" runat="server">
        <table class="fixedTable" cellpadding="0" cellspacing="0" border="0">
          <colgroup>
            <col width="5%" />
            <col style="width: 35%;" />
            <col style="width: 20%;" />
            <col style="width: 35%;" />
            <col width="5%" />
          </colgroup>
          <tr>
            <td rowspan="3">&nbsp;</td>
            <td rowspan="3">
              <p>
                <asp:DropDownList ID="listDept" runat="server" AutoPostBack="True" Width="100%" />
              </p>
              <p>
                <asp:ListBox ID="listAccount" runat="server" Width="100%" Height="350px" SelectionMode="Multiple" />
              </p>
            </td>
            <td style="text-align: center; vertical-align: middle;">
              <input class="buttoncss move_button" onclick="AddItem('<%= listTO.ClientID %>')" type="button" value=">>" />
              <input class="buttoncss move_button" onclick="RemoveItem('<%= listTO.ClientID %>')" type="button" value="<<" />
            </td>
            <td style="vertical-align: middle">
              <div>
                <b>收件人</b>
                <select id="listTO" runat="server" class="selectBox" multiple="true" size="5" />
              </div>
            </td>
            <td rowspan="3">&nbsp;</td>
          </tr>
          <tr>
            <td style="text-align: center; vertical-align: middle;">
              <input class="buttoncss move_button" onclick="AddItem('<%= listCC.ClientID %>')" type="button" value=">>" />
              <input class="buttoncss move_button" onclick="RemoveItem('<%= listCC.ClientID %>')" type="button" value="<<" />
            </td>
            <td style="vertical-align: middle">
              <div>
                <b>抄送人</b>
                <select id="listCC" runat="server" class="selectBox" multiple="true" size="5" />
              </div>
            </td>
          </tr>
          <tr>
            <td style="text-align: center; vertical-align: middle;">
              <input class="buttoncss move_button" onclick="AddItem('<%= listBCC.ClientID %>')" type="button" value=">>" />
              <input class="buttoncss move_button" onclick="RemoveItem('<%= listBCC.ClientID %>')" type="button" value="<<" />
            </td>
            <td style="vertical-align: middle">
              <div>
                <b>秘送</b>
                <select id="listBCC" runat="server" class="selectBox" multiple="true" size="5" />
              </div>
            </td>
          </tr>
        </table>
        <p style="text-align: center;">
          <input class="buttoncss" style="width: 80px; height: 24px;" onclick="SaveData()" type="button" value="确定" />
          <input class="buttoncss" style="width: 80px; height: 24px;" onclick="window.close()" type="button" value="取消" />
        </p>
      </form>
    </td>
  </tr>
</table>
</body>
</html>
